985B - Switches and Lamps - CodeForces Solution


implementation *1200

Please click on ads to support us..

Python Code:

def solve():
        n, m = map(int, input().split())
        s = []
        cnt = [0]*m

    for i in range(n):
        s.append(list(input().strip()))
        for j in range(m):
            if s[i][j] == '1':
                cnt[j] += 1 
    for i in range(n):
        ok = True
                for j in range(m):
            if s[i][j] == '1' and cnt[j] == 1:
                ok = False
        if ok == True:             print("YES")
            return

        print("NO")

solve()

C++ Code:

/*
 * @author islam Mohamed Abououf
 */

#include "bits/stdc++.h"
using namespace std ;
#define ll long long
#define cin(v) for(auto &el : (v)) cin >> el
#define cout(v) for(auto &el : (v)) cout << el << ' ' ; cout << nl ;
#define Tc int t ; cin>>t ;while(t--)
#define all(vc) vc.begin() , (vc).end()
#define vi vector<int>
#define vii vector<pair<int , int>>
#define vvi vector<vector<int>>
#define mpii map<int,int>
#define mpll map<ll,ll>
#define vll  vector<ll>
#define nl '\n'
#define yes cout << "YES" << nl ;
#define no cout << "NO" << nl ;
#define _ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);


ll mod = 1e9+7;
int OO = 1e9;
ll N = 2e5+5 ;
vector<bool> isPrime(N,true);
set<ll> primes;
vi freq(N) ;

int get_divisors(ll num){
    set<ll> st ;
    for (ll i = 2; i*i <= num; ++i) {
        if(num%i == 0){
            st.insert(i) ;
            st.insert(num/i);
        }
    }
    return (int) st.size();
}
void sieve(){
    isPrime[0]= false ;
    isPrime[1]= false ;
    for (int i = 2; i <N ; ++i) {
        if(isPrime[i]){
            primes.insert(i) ;
            for (int j = i+i; j<N ; j+=i) {
                isPrime[j]= false ;
            }
        }
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}
ll fact(ll a){
    if(a==1)
        return a ;
    return a * fact(a-1) ;
}
ll lcm(ll a, ll b){
    return a/gcd(a,b)*b;
}
vector<string> switches ;
ll n,m;
vector<bool> dep(2005 , true) ;
void validate(){
    for (int i = 0; i <m; ++i) {
        int sum =0 , x = 0;
        for (int j = 0; j < n; ++j) {
            if(switches[j][i]=='1'){
                sum++ ;
                x = j ;
            }
        }
        if(sum==1) dep[x] = false;
    }
}
// 1 1
// 2 1
// 4 -1
// 5 1

void answer() {
    cin >> n>>m;
    for (int i = 0; i < n; ++i) {
        string x;
        cin >> x;
        switches.push_back(x);
    }
    validate() ;
    for (int i = 0; i < n; ++i) {
        if(dep[i]) {
            yes return;
        }
    }
    no
}

int main() {
    _
//    Tc{
//        answer() ;
//    }
    answer();

}
		 			  	 	    	 	 		  	   		


Comments

Submit
0 Comments
More Questions

39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction
1690E - Price Maximization
282B - Painting Eggs
440A - Forgotten Episode
233B - Non-square Equation
628B - New Skateboard
262B - Roma and Changing Signs
755C - PolandBall and Forest
456B - Fedya and Maths
376B - IOU
1623B - Game on Ranges
1118A - Water Buying
1462C - Unique Number
301A - Yaroslav and Sequence
38A - Army
38C - Blinds
1197A - DIY Wooden Ladder
1717D - Madoka and The Corruption Scheme
1296D - Fight with Monsters
729D - Sea Battle
788A - Functions again
1245B - Restricted RPS
1490D - Permutation Transformation
1087B - Div Times Mod
1213B - Bad Prices
1726B - Mainak and Interesting Sequence
1726D - Edge Split
1726C - Jatayu's Balanced Bracket Sequence